﻿using CommonTools;
using CommonTools.Messages;
using CommunityToolkit.Mvvm.Messaging;
using Database.ERPNext;
using Main.Models;
using MySqlConnector;
using OpenCvSharp;
using Renci.SshNet;
using System.Configuration;
using System.Data;
using System.Net;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices.JavaScript;
using System.Runtime.Intrinsics.Arm;
using System.Security.Cryptography;
using System.Text;
using System.Windows;
using System.Windows.Threading;
using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames;

namespace Main
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : System.Windows.Application
    {


        public App()
        {

            ////注意：用Task.Run不行
            //ThreadPool.QueueUserWorkItem(delegate
            //{
            //    SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
            //    SynchronizationContext.Current!.Post(async pl =>
            //    {
            //        //里面写真正的业务内容
            //        string usr1 = await ERPNextAuthentication.Authentication.GetUserByTokenFile("D:\\ERPNext实施\\张锦.token");

            //        string usr2 = await ERPNextAuthentication.Authentication.GetUserByPassword("15841115316", "shyq1234");
            //    }, null);
            //});

           
            


            //var items = ExcelHelper.ExcelHelper.LoadItemsFromExcelFile<GL_Entry_ForInPut>("d:\\in.xlsx", "日记账凭证");
        }

        protected override void OnExit(ExitEventArgs e)
        {
            try
            {
                Database.ERPNext.ERPNextDbContext.Current.Dispose();
                Serilog.Log.Information("【系统】退出进程");
                WeakReferenceMessenger.Default.Send(new OnExitAppMessage());
            }
            catch(Exception ex) {
                Serilog.Log.Error($"【系统】错误：{ex.Message}");
            }
            
            base.OnExit(e);
        }
    }



}
